﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Galaxy.AutoCAD.Options;

namespace Galaxy.AutoCAD.Windows
{
    public partial class OpeningStirrupWindows : Form
    {
        public OpeningStirrupWindows()
        {
            InitializeComponent();
        }

        private void OpeningStirrupWindows_Load(object sender, EventArgs e)
        {
            this.textBox1.Focus();
            this.textBox1.Text = "15";
            this.comboBox1.Items.Add("HPB300");
            this.comboBox1.Items.Add("HRB335");
            this.comboBox1.Items.Add("HRB400");
            this.comboBox1.Items.Add("HRBF400");
            this.comboBox1.Items.Add("HRB500");
            this.comboBox1.Items.Add("HRBF500");
            if (this.comboBox1.Items.Count > 0)
            {
                if (this.comboBox1.Items.Contains("HRB400"))
                {
                    this.comboBox1.SelectedItem = "HRB400";
                }
                else
                {
                    this.comboBox1.SelectedItem = comboBox1.Items[0];
                }
            }
            this.comboBox2.Items.Add("6");
            this.comboBox2.Items.Add("8");
            this.comboBox2.Items.Add("10");
            this.comboBox2.Items.Add("12");
            if (this.comboBox2.Items.Count > 0)
            {
                if (this.comboBox2.Items.Contains("8"))
                {
                    this.comboBox2.SelectedItem = "8";
                }
                else
                {
                    this.comboBox2.SelectedItem = comboBox1.Items[0];
                }
            }
            this.radioButton1.Checked = true;
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            this.textBox1.SelectAll();
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
            this.comboBox1.SelectAll();
        }

        private void comboBox2_Click(object sender, EventArgs e)
        {
            this.comboBox2.SelectAll();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RebarOptionTool.OpeningStirrupPass = "1";
            uint openingStirrupCoveringLayer;
            if (uint.TryParse(textBox1.Text, out openingStirrupCoveringLayer))
            {
                RebarOptionTool.OpeningStirrupCoveringLayer = openingStirrupCoveringLayer;
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请输入有效值!");
                textBox1.Focus();
                return;
            }
            if (comboBox1.SelectedItem == null)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择有效值!");
                comboBox1.Focus();
                return;
            }
            else
            {
                RebarOptionTool.OpeningStirrupGrade = comboBox1.Text;
            }
            if (comboBox2.SelectedItem == null)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择有效值!");
                comboBox2.Focus();
                return;
            }
            else
            {
                RebarOptionTool.OpeningStirrupDirect = Convert.ToUInt32(comboBox2.Text);
            }
            if (radioButton1.Checked == false && radioButton2.Checked == false && radioButton3.Checked == false && radioButton4.Checked == false)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择有效的开口箍筋开口位置!");
                return;
            }
            else
            {
                if (radioButton1.Checked == true)
                {
                    RebarOptionTool.OpeningStirrupClosedPosition = "上";
                }
                if (radioButton2.Checked == true)
                {
                    RebarOptionTool.OpeningStirrupClosedPosition = "下";
                }
                if (radioButton3.Checked == true)
                {
                    RebarOptionTool.OpeningStirrupClosedPosition = "左";
                }
                if (radioButton4.Checked == true)
                {
                    RebarOptionTool.OpeningStirrupClosedPosition = "右";
                }
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RebarOptionTool.OpeningStirrupPass = "0";
            RebarOptionTool.OpeningStirrupCoveringLayer = 15;
            RebarOptionTool.OpeningStirrupGrade = "HRB400";
            RebarOptionTool.OpeningStirrupDirect = 8;
            RebarOptionTool.OpeningStirrupClosedPosition = "上";
            this.Close();
        }
    }
}
